import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DisplayAll {
	public static void displayAll(){
		String URL = "jdbc:mysql://localhost:3306/test";
		String driverName = "com.mysql.jdbc.Driver";
		String sql = "select stuno,name,birthdate from students";
		String userName = "root";//root
		String password = "kfc123456";//123456
		Connection conn = null;
		
		
		
		
		try {
			Class.forName(driverName);//jdbc4.0 ������ʹ������������ע�����
			conn = DriverManager.getConnection(URL,userName,password);
			Statement statement = conn.createStatement();
			ResultSet resultSet = statement.executeQuery(sql);
			// id | stuno     | name | gender | birthdate  | major
			while(resultSet.next()){
				//int id = resultSet.getInt("id");
				String stuno = resultSet.getString("stuno");
				String name=resultSet.getString("name");
				Date date = resultSet.getDate("birthdate");
				System.out.print(" stuno="+stuno+" name="+name+" birthdate="+date);
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(conn!=null)
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}//����ʹ��Try..with..resources�﷨��
			conn = null;
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		displayAll();
	}

}
